export default {
    state() {
        return {
            tagsList:[
                {
                    title: "首页",
                    path: "/home/echarts"
                }
            ],
            tagIndex: 0
        }
    },
    mutations: {

        addTagsRoute(state, val){
            // 如果标签页数组tagsList里面存在已点击过的标签 点亮对应标签去 否则不存在再添加进去
            // console.log(state.tagsList.indexOf(val))
            // console.log(JSON.stringify(state.tagsList).indexOf(JSON.stringify(val)))
            // console.log(state.tagsList.findIndex(el => el.path == val.path))
            if (state.tagsList.findIndex(el => el.path == val.path) == -1) {
                state.tagsList.push(val);
                state.tagIndex = state.tagsList.length - 1;
            } else {
                state.tagIndex = state.tagsList.findIndex(el => el.path == val.path)
            }
            
        },
        setTagIndex(state, val){
            state.tagIndex = val
        },
        removeTagRoute(state,val){
            state.tagsList.splice(state.tagsList.findIndex(el => el.path == val.path),1)
        }
    },
    actions: {
        getAddTagsRoute(context, val) {
            context.commit("addTagsRoute", val)
        },
        getSetTagIndex(context,val){
            context.commit("setTagIndex",val)
        },
        getRemoveTagRoute(context,val){
            context.commit('removeTagRoute',val)
        }
    }
}